﻿<!DOCTYPE html>
<html lang="zh_CN">
<head>
    <#-- Freemark的包含指令 -->
    <#include "../common/header.ftl"/>
    <script src="/js/My97DatePicker/WdatePicker.js"></script>
    <script src="/js/plugins/common.js"></script>
<script>
   $(function () {
       //给查看文章绑定点击事件
       $(".showContentBtn").click(function () {
           //获取绑定的id
           var id = $(this).data("id");
           //发送请求获取文章内容
           $.get("/travel/concent.do",{id:id},function (data) {
               //将文章内容渲染进模态框中
               $("#contentModal .modal-body").html(data.content);
               //显示模态框
               $("#contentModal").modal('show');
           })
       });

       //发布和拒绝按钮
       $(".changeStateBtn").click(function () {
           //获取绑定的id和状态
           var id = $(this).data("id");
           var state = $(this).data("state");
           //发送ajax请求修改游记状态
           $.get("/travel/changeState.do",{id:id,state:state},function (data) {
               if (data.success) {
                   window.location.href="/travelCommend/list.do";
               }
           })
       });
       //给模态框的时间输入框绑定日历插件
       $("#inputModal input[name='schedule']").click(function () {
           WdatePicker({
               readOnly:true,
               minDate:new Date()
           });
       });
       //给推荐按钮绑定点击事件
       $(".hotBtn").click(function () {
           //进行回显
           var json = $(this).data("json");
           console.log(json);
           $("#editForm input[name='travel.id']").val(json.id);
           $("#editForm input[name='title']").val(json.title);
           $("#editForm img[id='coverUrl']").prop("src",json.coverUrl);
           $("#editForm input[name='coverUrl']").val(json.coverUrl);
           //触发模态框
           $("#inputModal").modal('show');
       });
       //给模态框保存按钮绑定点击事件,提交表单
       $(".modalBtn").click(function () {
           //发送ajax请求,提交表单
           //将表单的提交方式修改为ajax异步提交
           $("#editForm").ajaxSubmit(function (data) {
               if(data.success){
                   $.messager.alert("温馨提示","操作成功,1.5S之后关闭");
                   setTimeout(function () {
                       window.location.reload();
                   },1500);
               }
           })
       });
   })
</script>
</head>
<body>

<div class="container " style="margin-top: 20px">
    <#--欢迎-->
    <#include "../common/top.ftl"/>

    <div class="row">
        <div class="col-sm-3">
            <#-- Freemark设置共享变量的指令 -->
            <#assign menu="releaseList"/>
            <#--左侧菜单-->
            <#include "../common/menu.ftl"/>
        </div>
        <div class="col-sm-9">
            <div class="row">
                <div class="col-sm-12">
                    <h1 class="page-head-line">已发布游记列表</h1>
                </div>
            </div>
            <#-- 高级查询 -->
            <form class="form-inline" id="searchForm" action="/travel/releaseList.do" method="post">
                <input type="hidden" name="currentPage" id="currentPage" value="1">
                <input type="hidden" name="currentPage" name="id">
            </form>

            <table class="table table-striped table-hover" >
                <thead>
                <tr>
                    <th>编号</th>
                    <th>标题</th>
                    <th>封面</th>
                    <th>地点</th>
                    <th>作者</th>
                    <th>发布时间</th>
                    <th>状态</th>
                    <th></th>
                </tr>
                </thead>
            <#-- Freemark指令做循环迭代 -->
                <#list pageInfo.list as entity>
                    <tr>
                        <td>${entity_index + 1}</td>
                        <td>${(entity.title)!}</td>
                        <td><img src="${(entity.coverUrl)!}" width="30px"/></td>
                        <td>${(entity.place.name)!}</td>
                        <td>${(entity.author.nickName)!}</td>
                        <td>${((entity.releaseTime)?string('yyyy-MM-dd HH:mm:ss'))!}</td>
                        <td>${(entity.stateName)!}</td>
                        <td>
                            <a class="btn btn-info btn-xs btn-input showContentBtn" data-id="${entity.id}">
                                <span class="glyphicon glyphicon-pencil" ></span>查看文章
                            </a>
                            <a class="btn btn-danger btn-xs btn-input changeStateBtn" data-id="${entity.id}" data-state="1">
                                <span class="glyphicon glyphicon-pencil"></span>取消发布
                            </a>
                            <a class="btn btn-warning btn-xs btn-input hotBtn" data-json='${entity.json}'>
                                <span class="glyphicon glyphicon-pencil"></span>推荐
                            </a>
                        </td>
                    </tr>
                </#list>
            </table>

            <#--分页-->
            <#include "../common/page.ftl" />
        </div>
    </div>
</div><#--推荐游记的模态框-->
<div class="modal fade" id="inputModal" tabindex="-1" role="dialog">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title">新增游记推荐</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" action="/travelCommend/saveOrUpdate.do" method="post" id="editForm" enctype="multipart/form-data">
                    <input type="hidden" name="id" >
                    <div class="form-group">
                        <label for="name" class="col-sm-4 control-label">标题：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" id="title" name="title" >
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="name" class="col-sm-4 control-label">副标题：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" id="subTitle" name="subTitle" >
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="sn" class="col-sm-4 control-label">封面：</label>
                        <div class="col-sm-6">
                            <img id="coverUrl" width="100%"/>
                            <input type="file" class="form-control" name="file" >
                            <input type="hidden" class="form-control" name="coverUrl" >
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="sn" class="col-sm-4 control-label">推荐时间：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" id="schedule" name="schedule" >
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="sn" class="col-sm-4 control-label">推荐类型：</label>
                        <div class="col-sm-6">
                            <select id="auditState" class="form-control" autocomplete="off" name="type" >
                                <option value="1">每周推荐</option>
                                <option value="2">每月推荐</option>
                                <option value="3">攻略推荐</option>
                            </select>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                <button type="button" class="btn btn-primary btn-submit modalBtn">保存</button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div><!-- /.modal -->
<#--查看文章的模态框-->
<div class="modal fade" id="contentModal" tabindex="-1" role="dialog">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title">文章内容</h4>
            </div>
            <div class="modal-body">
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div><!-- /.modal -->
<#--设置模态框的图片大小-->
<style>
    #contentModal img{
        width: 100%
    }
</style>
</body>
</html>